package com.magnificent.atlantis.server.ui;

import com.magnificent.atlantis.server.resources.AtlantisServerResources;
import com.magnificent.atlantis.server.ui.panels.interaction.UserInteractionPanel;
import com.magnificent.atlantis.server.ui.panels.logger.LoggerPanel;
import com.magnificent.atlantis.server.ui.panels.user.UserPanel;

import javax.swing.*;
import java.awt.*;

/**
 * ServerUser: Babanin
 * Date: 25.03.2009
 * Time: 19:58:07
 */
public class MainFrame extends JFrame {

    private UserPanel userPanel;
    private LoggerPanel loggerPanel;
    private UserInteractionPanel userInteractionPanel;

    private JTabbedPane tabbedPane;

    public MainFrame() throws HeadlessException {
        init();
        initControls();
        initView();
    }

    private void init() {
        setTitle("xScheduler Server");
        setLayout(new BorderLayout());
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setIconImage(AtlantisServerResources.ICON.getImage());
    }

    private void initView() {
        setPreferredSize(new Dimension(800, 600));
        add(tabbedPane, BorderLayout.CENTER);
        pack();

        setLocationRelativeTo(null);
    }

    private void initControls() {
        userPanel = new UserPanel();
        loggerPanel = new LoggerPanel();
        userInteractionPanel = new UserInteractionPanel();

        tabbedPane = new JTabbedPane();

        tabbedPane.addTab("Users", userPanel);
        tabbedPane.addTab("Users interaction", userInteractionPanel);
        tabbedPane.addTab("Server log", loggerPanel);
    }

    public static MainFrame findMainFrame() {
        for (Frame frame : Frame.getFrames()) {
            if (frame instanceof MainFrame) {
                return (MainFrame) frame;
            }
        }

        return null;
    }
}
